home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / XLISP_2 / XLISP.DOC
Text File  |  1988-04-21  |  67KB  |  2,062 lines

  1. Posted-Date: Wed, 20 Apr 88 08:45:13 EDT
  2. Received-Date: Wed, 20 Apr 88 08:47:23 edt
  3. Return-Path: <ephraim@Think.COM>
  4. Received: from vidar.think.com ([192.31.180.22]) by Think.COM; Wed, 20 Apr 88 08:45:23 EDT
  5. Received: by vidar.think.com; Wed, 20 Apr 88 08:45:17 EDT
  6. From: ephraim@Think.COM
  7. Message-Id: <8804201245.AA09507@vidar.think.com>
  8. To: hodas@eniac.seas.upenn.edu
  9. Subject: XLISP 2.0 documentation
  10. Date: Wed, 20 Apr 88 08:45:13 EDT
  11.  
  12.  
  13. This file has been compressed for mailing as follows:
  14.  
  15. Leading white space has been changed from spaces to tabs at the rate
  16. of one tab per eight spaces.
  17. The first tab on each line has been deleted.
  18. Trailing white space has been deleted.
  19. Page breaks are marked by form-feeds (control-L) instead of by vast
  20. areas of white space.
  21.  
  22.  
  23.  
  24.  
  25.  
  26.          XLISP: An Object-oriented Lisp
  27.  
  28.               Version 2.0
  29.  
  30.             February 6, 1988
  31.  
  32.  
  33.                    by
  34.                David Michael Betz
  35.             127 Taylor Road
  36.              Peterborough, NH 03458
  37.  
  38.              (603) 924-6936 (home)
  39.  
  40.        Copyright (c) 1988, by David Michael Betz
  41.               All Rights Reserved
  42.    Permission is granted for unrestricted non-commercial use
  43.  
  44.  
  45.  
  46.  
  47. XLISP                  TABLE OF CONTENTS                  Page 2
  48.  
  49.  
  50.                Table of Contents
  51.  
  52.  
  53.     TABLE OF CONTENTS                        2
  54.  
  55.     INTRODUCTION                             4
  56.  
  57.     A NOTE FROM THE AUTHOR                   5
  58.  
  59.     XLISP COMMAND LOOP                       6
  60.  
  61.     BREAK COMMAND LOOP                       7
  62.  
  63.     DATA TYPES                               8
  64.  
  65.     THE EVALUATOR                            9
  66.  
  67.     LEXICAL CONVENTIONS                     10
  68.  
  69.     READTABLES                              11
  70.  
  71.     LAMBDA LISTS                            12
  72.  
  73.     OBJECTS                                 14
  74.  
  75.     SYMBOLS                                 17
  76.  
  77.     EVALUATION FUNCTIONS                    18
  78.  
  79.     SYMBOL FUNCTIONS                        19
  80.  
  81.     PROPERTY LIST FUNCTIONS                 21
  82.  
  83.     ARRAY FUNCTIONS                         22
  84.  
  85.     LIST FUNCTIONS                          23
  86.  
  87.     DESTRUCTIVE LIST FUNCTIONS              26
  88.  
  89.     PREDICATE FUNCTIONS                     27
  90.  
  91.     CONTROL CONSTRUCTS                      29
  92.  
  93.     LOOPING CONSTRUCTS                      31
  94.  
  95.     THE PROGRAM FEATURE                     32
  96.  
  97.     DEBUGGING AND ERROR HANDLING            33
  98.  
  99.     ARITHMETIC FUNCTIONS                    34
  100.  
  101.     BITWISE LOGICAL FUNCTIONS               36
  102.  
  103.     STRING FUNCTIONS                        37
  104.  
  105.  
  106.  
  107.  
  108. XLISP                  TABLE OF CONTENTS                  Page 3
  109.  
  110.  
  111.     CHARACTER FUNCTIONS                     39
  112.  
  113.     INPUT/OUTPUT FUNCTIONS                  41
  114.  
  115.     THE FORMAT FUNCTION                     42
  116.  
  117.     FILE I/O FUNCTIONS                      43
  118.  
  119.     STRING STREAM FUNCTIONS                 44
  120.  
  121.     SYSTEM FUNCTIONS                        45
  122.  
  123.     EXAMPLES                                47
  124.  
  125.  
  126.  
  127.  
  128. XLISP                     INTRODUCTION                    Page 4
  129.  
  130.  
  131. INTRODUCTION
  132.  
  133. XLISP is an experimental programming language combining some of
  134. the features of Common Lisp with an object-oriented extension
  135. capability.  It was implemented to allow experimentation with
  136. object-oriented programming on small computers.
  137.  
  138. There are currently implementations of XLISP running on the IBM-
  139. PC and clones under MS-DOS, on the Macintosh, the Atari-ST and
  140. the Amiga.  It is completely written in the programming language
  141. 'C' and is easily extended with user written built-in functions
  142. and classes.  It is available in source form to non-commercial
  143. users.
  144.  
  145. Many Common Lisp functions are built into XLISP.  In addition,
  146. XLISP defines the objects 'Object' and 'Class' as primitives.
  147. 'Object' is the only class that has no superclass and hence is
  148. the root of the class heirarchy tree.  'Class' is the class of
  149. which all classes are instances (it is the only object that is
  150. an instance of itself).
  151.  
  152. This document is a brief description of XLISP.  It assumes some
  153. knowledge of LISP and some understanding of the concepts of
  154. object-oriented programming.
  155.  
  156. I recommend the book "LISP" by Winston and Horn and published by
  157. Addison Wesley for learning Lisp.  The first edition of this
  158. book is based on MacLisp and the second edition is based on
  159. Common Lisp.  XLISP will continue to migrate towards
  160. compatibility with Common Lisp.
  161.  
  162. You will probably also need a copy of "Common Lisp: The
  163. Language" by Guy L. Steele, Jr., published by Digital Press to
  164. use as a reference for some of the Common Lisp functions that
  165. are described only briefly in this document.
  166.  
  167.  
  168.  
  169.  
  170. XLISP                A NOTE FROM THE AUTHOR               Page 5
  171.  
  172.  
  173. A NOTE FROM THE AUTHOR
  174.  
  175. If you have any problems with XLISP, feel free to contact me for
  176. help or advice.  Please remember that since XLISP is available
  177. in source form in a high level language, many users have been
  178. making versions available on a variety of machines.  If you call
  179. to report a problem with a specific version, I may not be able
  180. to help you if that version runs on a machine to which I don't
  181. have access.  Please have the version number of the version that
  182. you are running readily accessible before calling me.
  183.  
  184. If you find a bug in XLISP, first try to fix the bug yourself
  185. using the source code provided.  If you are successful in fixing
  186. the bug, send the bug report along with the fix to me.  If you
  187. don't have access to a C compiler or are unable to fix a bug,
  188. please send the bug report to me and I'll try to fix it.
  189.  
  190. Any suggestions for improvements will be welcomed.  Feel free to
  191. extend the language in whatever way suits your needs.  However,
  192. PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
  193. FIRST!!  I would like to be the clearing house for new features
  194. added to XLISP.  If you want to add features for your own
  195. personal use, go ahead.  But, if you want to distribute your
  196. enhanced version, contact me first.  Please remember that the
  197. goal of XLISP is to provide a language to learn and experiment
  198. with LISP and object-oriented programming on small computers.  I
  199. don't want it to get so big that it requires megabytes of memory
  200. to run.
  201.  
  202.  
  203.  
  204.  
  205. XLISP                 XLISP COMMAND LOOP                  Page 6
  206.  
  207.  
  208. XLISP COMMAND LOOP
  209.  
  210. When XLISP is started, it first tries to load the workspace
  211. "xlisp.wks" from the current directory.  If that file doesn't
  212. exist, XLISP builds an initial workspace, empty except for the
  213. built-in functions and symbols.
  214.  
  215. Then XLISP attempts to load "init.lsp" from the current
  216. directory.  It then loads any files named as parameters on the
  217. command line (after appending ".lsp" to their names).
  218.  
  219. XLISP then issues the following prompt:
  220.  
  221. >
  222.  
  223. This indicates that XLISP is waiting for an expression to be
  224. typed.
  225.  
  226. When a complete expression has been entered, XLISP attempts to
  227. evaluate that expression.  If the expression evaluates
  228. successfully, XLISP prints the result and then returns to the
  229. initial prompt waiting for another expression to be typed.
  230.  
  231.  
  232.  
  233.  
  234. XLISP                 BREAK COMMAND LOOP                  Page 7
  235.  
  236.  
  237. BREAK COMMAND LOOP
  238.  
  239. When XLISP encounters an error while evaluating an expression,
  240. it attempts to handle the error in the following way:
  241.  
  242. If the symbol '*breakenable*' is true, the message corresponding
  243. to the error is printed.  If the error is correctable, the
  244. correction message is printed.
  245.  
  246. If the symbol '*tracenable*' is true, a trace back is printed.
  247. The number of entries printed depends on the value of the symbol
  248. '*tracelimit*'.  If this symbol is set to something other than a
  249. number, the entire trace back stack is printed.
  250.  
  251. XLISP then enters a read/eval/print loop to allow the user to
  252. examine the state of the interpreter in the context of the
  253. error.  This loop differs from the normal top-level
  254. read/eval/print loop in that if the user invokes the function
  255. 'continue', XLISP will continue from a correctable error.  If
  256. the user invokes the function 'clean-up', XLISP will abort the
  257. break loop and return to the top level or the next lower
  258. numbered break loop.  When in a break loop, XLISP prefixes the
  259. break level to the normal prompt.
  260.  
  261. If the symbol '*breakenable*' is nil, XLISP looks for a
  262. surrounding errset function.  If one is found, XLISP examines
  263. the value of the print flag.  If this flag is true, the error
  264. message is printed.  In any case, XLISP causes the errset
  265. function call to return nil.
  266.  
  267. If there is no surrounding errset function, XLISP prints the
  268. error message and returns to the top level.
  269.  
  270.  
  271.  
  272.  
  273. XLISP                      DATA TYPES                     Page 8
  274.  
  275.  
  276. DATA TYPES
  277.  
  278. There are several different data types available to XLISP
  279. programmers.
  280.  
  281.     o lists
  282.     o symbols
  283.     o strings
  284.     o integers
  285.     o characters
  286.     o floats
  287.     o objects
  288.     o arrays
  289.     o streams
  290.     o subrs (built-in functions)
  291.     o fsubrs (special forms)
  292.     o closures (user defined functions)
  293.  
  294.  
  295.  
  296.  
  297. XLISP                    THE EVALUATOR                    Page 9
  298.  
  299.  
  300. THE EVALUATOR
  301.  
  302. The process of evaluation in XLISP:
  303.  
  304. Strings, integers, characters, floats, objects, arrays, streams,
  305. subrs, fsubrs and closures evaluate to themselves.
  306.  
  307. Symbols act as variables and are evaluated by retrieving the
  308. value associated with their current binding.
  309.  
  310. Lists are evaluated by examining the first element of the list
  311. and then taking one of the following actions:
  312.  
  313.     If it is a symbol, the functional binding of the symbol is
  314.     retrieved.
  315.  
  316.     If it is a lambda expression, a closure is constructed for
  317.     the function described by the lambda expression.
  318.  
  319.     If it is a subr, fsubr or closure, it stands for itself.
  320.  
  321.     Any other value is an error.
  322.  
  323. Then, the value produced by the previous step is examined:
  324.  
  325.     If it is a subr or closure, the remaining list elements are
  326.     evaluated and the subr or closure is called with these
  327.     evaluated expressions as arguments.
  328.  
  329.     If it is an fsubr, the fsubr is called using the remaining
  330.     list elements as arguments (unevaluated).
  331.  
  332.     If it is a macro, the macro is expanded using the remaining
  333.     list elements as arguments (unevaluated).  The macro
  334.     expansion is then evaluated in place of the original macro
  335.     call.
  336.  
  337.  
  338.  
  339.  
  340. XLISP                 LEXICAL CONVENTIONS                Page 10
  341.  
  342.  
  343. LEXICAL CONVENTIONS
  344.  
  345. The following conventions must be followed when entering XLISP
  346. programs:
  347.  
  348. Comments in XLISP code begin with a semi-colon character and
  349. continue to the end of the line.
  350.  
  351. Symbol names in XLISP can consist of any sequence of non-blank
  352. printable characters except the following:
  353.  
  354.     ( ) ' ` , " ;
  355.  
  356. Uppercase and lowercase characters are not distinguished within
  357. symbol names.  All lowercase characters are mapped to uppercase
  358. on input.
  359.  
  360. Integer literals consist of a sequence of digits optionally
  361. beginning with a '+' or '-'.  The range of values an integer can
  362. represent is limited by the size of a C 'long' on the machine on
  363. which XLISP is running.
  364.  
  365. Floating point literals consist of a sequence of digits
  366. optionally beginning with a '+' or '-' and including an embedded
  367. decimal point.  The range of values a floating point number can
  368. represent is limited by the size of a C 'float' ('double' on
  369. machines with 32 bit addresses) on the machine on which XLISP is
  370. running.
  371.  
  372. Literal strings are sequences of characters surrounded by double
  373. quotes.  Within quoted strings the '\' character is used to
  374. allow non-printable characters to be included.  The codes
  375. recognized are:
  376.  
  377.     \\        means the character '\'
  378.     \n       means newline
  379.     \t       means tab
  380.     \r       means return
  381.     \f       means form feed
  382.     \nnn     means the character whose octal code is nnn
  383.  
  384.  
  385.  
  386.  
  387. XLISP                      READTABLES                    Page 11
  388.  
  389.  
  390. READTABLES
  391.  
  392. The behaviour of the reader is controlled by a data structure
  393. called a "readtable".  The reader uses the symbol *READTABLE* to
  394. locate the current readtable.  This table controls the
  395. interpretation of input characters.  It is an array with 128
  396. entries, one for each of the ASCII character codes.  Each entry
  397. contains one of the following things:
  398.  
  399.     NIL             Indicating an invalid character
  400.     :CONSTITUENT    Indicating a symbol constituent
  401.     :WHITE-SPACE    Indicating a whitespace character
  402.     (:TMACRO . fun) Terminating readmacro
  403.     (:NMACRO . fun) Non-terminating readmacro
  404.     :SESCAPE        Single escape character ('\')
  405.     :MESCAPE        Multiple escape character ('|')
  406.  
  407. In the case of :TMACRO and :NMACRO, the "fun" component is a
  408. function.  This can either be a built-in readmacro function or a
  409. lambda expression.  The function should take two parameters.
  410. The first is the input stream and the second is the character
  411. that caused the invocation of the readmacro.  The readmacro
  412. function should return NIL to indicate that the character should
  413. be treated as white space or a value consed with NIL to indicate
  414. that the readmacro should be treated as an occurance of the
  415. specified value.  Of course, the readmacro code is free to read
  416. additional characters from the input stream.
  417.  
  418. XLISP defines several useful read macros:
  419.  
  420.     '<expr>         == (quote <expr>)
  421.     #'<expr>        == (function <expr>)
  422.     #(<expr>...)    == an array of the specified expressions
  423.     #x<hdigits>     == a hexadecimal number (0-9,A-F)
  424.     #o<odigits>     == an octal number (0-7)
  425.     #b<bdigits>     == a binary number (0-1)
  426.     #\<char> == the ASCII code of the character
  427.     #| ... |#       == a comment
  428.     #:<symbol>      == an uninterned symbol
  429.     `<expr>         == (backquote <expr>)
  430.     ,<expr>         == (comma <expr>)
  431.     ,@<expr>        == (comma-at <expr>)
  432.  
  433.  
  434.  
  435.  
  436. XLISP                     LAMBDA LISTS                   Page 12
  437.  
  438.  
  439. LAMBDA LISTS
  440.  
  441. There are several forms in XLISP that require that a "lambda
  442. list" be specified.  A lambda list is a definition of the
  443. arguments accepted by a function.  There are four different
  444. types of arguments.
  445.  
  446. The lambda list starts with required arguments.  Required
  447. arguments must be specified in every call to the function.
  448.  
  449. The required arguments are followed by the &optional arguments.
  450. Optional arguments may be provided or omitted in a call.  An
  451. initialization expression may be specified to provide a default
  452. value for an &optional argument if it is omitted from a call.
  453. If no initialization expression is specified, an omitted
  454. argument is initialized to NIL.  It is also possible to provide
  455. the name of a 'supplied-p' variable that can be used to
  456. determine if a call provided a value for the argument or if the
  457. initialization expression was used.  If specified, the supplied-
  458. p variable will be bound to T if a value was specified in the
  459. call and NIL if the default value was used.
  460.  
  461. The &optional arguments are followed by the &rest argument.  The
  462. &rest argument gets bound to the remainder of the argument list
  463. after the required and &optional arguments have been removed.
  464.  
  465. The &rest argument is followed by the &key arguments.  When a
  466. keyword argument is passed to a function, a pair of values
  467. appears in the argument list.  The first expression in the pair
  468. should evaluate to a keyword symbol (a symbol that begins with a
  469. ':').  The value of the second expression is the value of the
  470. keyword argument.  Like &optional arguments, &key arguments can
  471. have initialization expressions and supplied-p variables.  In
  472. addition, it is possible to specify the keyword to be used in a
  473. function call.  If no keyword is specified, the keyword obtained
  474. by adding a ':' to the beginning of the keyword argument symbol
  475. is used.  In other words, if the keyword argument symbol is
  476. 'foo', the keyword will be ':foo'.
  477.  
  478. The &key arguments are followed by the &aux variables.  These
  479. are local variables that are bound during the evaluation of the
  480. function body.  It is possible to have initialization
  481. expressions for the &aux variables.
  482.  
  483.  
  484.  
  485.  
  486. XLISP                     LAMBDA LISTS                   Page 13
  487.  
  488.  
  489. Here is the complete syntax for lambda lists:
  490.  
  491.     (<rarg>...
  492.      [&optional [<oarg> | (<oarg> [<init> [<svar>]])]...]
  493.      [&rest <rarg>]
  494.      [&key
  495.        [<karg> | ([<karg> | (<key> <karg>)] [<init> [<svar>]])]...
  496.        &allow-other-keys]
  497.      [&aux
  498.        [<aux> | (<aux> [<init>])]...])
  499.  
  500.     where:
  501.  
  502.     <rarg>  is a required argument symbol
  503.     <oarg>  is an &optional argument symbol
  504.     <rarg>  is the &rest argument symbol
  505.     <karg>  is a &key argument symbol
  506.     <key>   is a keyword symbol
  507.     <aux>   is an auxiliary variable symbol
  508.     <init>  is an initialization expression
  509.     <svar>  is a supplied-p variable symbol
  510.  
  511.  
  512.  
  513.  
  514. XLISP                       OBJECTS                      Page 14
  515.  
  516.  
  517. OBJECTS
  518.  
  519. Definitions:
  520.  
  521.     o selector - a symbol used to select an appropriate method
  522.     o message - a selector and a list of actual arguments
  523.     o method - the code that implements a message
  524.  
  525. Since XLISP was created to provide a simple basis for
  526. experimenting with object-oriented programming, one of the
  527. primitive data types included is 'object'.  In XLISP, an object
  528. consists of a data structure containing a pointer to the
  529. object's class as well as an array containing the values of the
  530. object's instance variables.
  531.  
  532. Officially, there is no way to see inside an object (look at the
  533. values of its instance variables).  The only way to communicate
  534. with an object is by sending it a message.
  535.  
  536. You can send a message to an object using the 'send' function.
  537. This function takes the object as its first argument, the
  538. message selector as its second argument (which must be a symbol)
  539. and the message arguments as its remaining arguments.
  540.  
  541. The 'send' function determines the class of the receiving object
  542. and attempts to find a method corresponding to the message
  543. selector in the set of messages defined for that class.  If the
  544. message is not found in the object's class and the class has a
  545. super-class, the search continues by looking at the messages
  546. defined for the super-class.  This process continues from one
  547. super-class to the next until a method for the message is found.
  548. If no method is found, an error occurs.
  549.  
  550. A message can also be sent from the body of a method by using
  551. the current object, but the method lookup starts with the
  552. object's superclass rather than its class.  This allows a
  553. subclass to invoke a standard method in its parent class even
  554. though it overrides that method with its own specialized
  555. version.
  556.  
  557. When a method is found, the evaluator binds the receiving object
  558. to the symbol 'self' and evaluates the method using the
  559. remaining elements of the original list as arguments to the
  560. method.  These arguments are always evaluated prior to being
  561. bound to their corresponding formal arguments.  The result of
  562. evaluating the method becomes the result of the expression.
  563.  
  564.  
  565.  
  566.  
  567. XLISP                       OBJECTS                      Page 15
  568.  
  569.  
  570. THE 'Object' CLASS
  571.  
  572. Classes:
  573.  
  574. Object  THE TOP OF THE CLASS HEIRARCHY
  575.  
  576.     Messages:
  577.  
  578.     :show  SHOW AN OBJECT'S INSTANCE VARIABLES
  579.         returns     the object
  580.  
  581.     :class  RETURN THE CLASS OF AN OBJECT
  582.         returns     the class of the object
  583.  
  584.     :isnew  THE DEFAULT OBJECT INITIALIZATION ROUTINE
  585.         returns     the object
  586.  
  587.     :sendsuper <sel> <args>...  SEND SUPERCLASS A MESSAGE
  588.         <sel>       the message selector
  589.         <args>      the message arguments
  590.         returns     the result of sending the message
  591.  
  592.  
  593.  
  594.  
  595. XLISP                       OBJECTS                      Page 16
  596.  
  597.  
  598. THE 'Class' CLASS
  599.  
  600. Class   THE CLASS OF ALL OBJECT CLASSES (including itself)
  601.  
  602.     Messages:
  603.  
  604.     :new  CREATE A NEW INSTANCE OF A CLASS
  605.         returns     the new class object
  606.  
  607.     :isnew <ivars> [<cvars> [<super>]]  INITIALIZE A NEW CLASS
  608.         <ivars>     the list of instance variable symbols
  609.         <cvars>     the list of class variable symbols
  610.         <super>     the superclass (default is Object)
  611.         returns     the new class object
  612.  
  613.     :answer <msg> <fargs> <code>  ADD A MESSAGE TO A CLASS
  614.         <msg>       the message symbol
  615.         <fargs>     the formal argument list (lambda list)
  616.         <code>      a list of executable expressions
  617.         returns     the object
  618.  
  619.  
  620. When a new instance of a class is created by sending the message
  621. ':new' to an existing class, the message ':isnew' followed by
  622. whatever parameters were passed to the ':new' message is sent to
  623. the newly created object.
  624.  
  625. When a new class is created by sending the ':new' message to the
  626. object 'Class', an optional parameter may be specified
  627. indicating the superclass of the new class.  If this parameter
  628. is omitted, the new class will be a subclass of 'Object'.  A
  629. class inherits all instance variables, class variables, and
  630. methods from its super-class.
  631.  
  632.  
  633.  
  634.  
  635. XLISP                       SYMBOLS                      Page 17
  636.  
  637.  
  638. SYMBOLS
  639.  
  640.     o self - the current object (within a method context)
  641.     o *obarray* - the object hash table
  642.     o *standard-input* - the standard input stream
  643.     o *standard-output* - the standard output stream
  644.     o *error-output* - the error output stream
  645.     o *trace-output* - the trace output stream
  646.     o *debug-io* - the debug i/o stream
  647.     o *breakenable* - flag controlling entering break loop on errors
  648.     o *tracelist* - list of names of functions to trace
  649.     o *tracenable* - enable trace back printout on errors
  650.     o *tracelimit* - number of levels of trace back information
  651.     o *evalhook* - user substitute for the evaluator function
  652.     o *applyhook* - (not yet implemented)
  653.     o *readtable* - the current readtable
  654.     o *unbound* - indicator for unbound symbols
  655.     o *gc-flag* - controls the printing of gc messages
  656.     o *gc-hook* - function to call after garbage collection
  657.     o *integer-format* - format for printing integers ("%d" or "%ld")
  658.     o *float-format* - format for printing floats ("%g")
  659.     o *print-case* - symbol output case (:upcase or :downcase)
  660.  
  661. There are several symbols maintained by the read/eval/print
  662. loop.  The symbols '+', '++', and '+++' are bound to the most
  663. recent three input expressions.  The symbols '*', '**' and '***'
  664. are bound to the most recent three results.  The symbol '-' is
  665. bound to the expression currently being evaluated.  It becomes
  666. the value of '+' at the end of the evaluation.
  667.  
  668.  
  669.  
  670.  
  671. XLISP                 EVALUATION FUNCTIONS               Page 18
  672.  
  673.  
  674. EVALUATION FUNCTIONS
  675.  
  676. (eval <expr>)  EVALUATE AN XLISP EXPRESSION
  677.     <expr>      the expression to be evaluated
  678.     returns     the result of evaluating the expression
  679.  
  680. (apply <fun> <args>)  APPLY A FUNCTION TO A LIST OF ARGUMENTS
  681.     <fun>       the function to apply (or function symbol)
  682.     <args>      the argument list
  683.     returns     the result of applying the function to the arguments
  684.  
  685. (funcall <fun> <arg>...)  CALL A FUNCTION WITH ARGUMENTS
  686.     <fun>       the function to call (or function symbol)
  687.     <arg>       arguments to pass to the function
  688.     returns     the result of calling the function with the arguments
  689.  
  690. (quote <expr>)  RETURN AN EXPRESSION UNEVALUATED
  691.     <expr>      the expression to be quoted (quoted)
  692.     returns     <expr> unevaluated
  693.  
  694. (function <expr>)  GET THE FUNCTIONAL INTERPRETATION
  695.     <expr>      the symbol or lambda expression (quoted)
  696.     returns     the functional interpretation
  697.  
  698. (backquote <expr>)  FILL IN A TEMPLATE
  699.     <expr>      the template
  700.     returns     a copy of the template with comma and comma-at
  701.         expressions expanded
  702.  
  703. (lambda <args> <expr>...)  MAKE A FUNCTION CLOSURE
  704.     <args>      formal argument list (lambda list) (quoted)
  705.     <expr>      expressions of the function body
  706.     returns     the function closure
  707.  
  708. (get-lambda-expression <closure>)  GET THE LAMBDA EXPRESSION
  709.     <closure>   the closure
  710.     returns     the original lambda expression
  711.  
  712. (macroexpand <form>)  RECURSIVELY EXPAND MACRO CALLS
  713.     <form>      the form to expand
  714.     returns     the macro expansion
  715.  
  716. (macroexpand-1 <form>)  EXPAND A MACRO CALL
  717.     <form>      the macro call form
  718.     returns     the macro expansion
  719.  
  720.  
  721.  
  722.  
  723. XLISP                   SYMBOL FUNCTIONS                 Page 19
  724.  
  725.  
  726. SYMBOL FUNCTIONS
  727.  
  728. (set <sym> <expr>)  SET THE VALUE OF A SYMBOL
  729.     <sym>       the symbol being set
  730.     <expr>      the new value
  731.     returns     the new value
  732.  
  733. (setq [<sym> <expr>]...)  SET THE VALUE OF A SYMBOL
  734.     <sym>       the symbol being set (quoted)
  735.     <expr>      the new value
  736.     returns     the new value
  737.  
  738. (psetq [<sym> <expr>]...)  PARALLEL VERSION OF SETQ
  739.     <sym>       the symbol being set (quoted)
  740.     <expr>      the new value
  741.     returns     the new value
  742.  
  743. (setf [<place> <expr>]...)  SET THE VALUE OF A FIELD
  744.     <place>     the field specifier (quoted):
  745.           <sym>                   set value of a symbol
  746.           (car <expr>)            set car of a cons node
  747.           (cdr <expr>)            set cdr of a cons node
  748.           (nth <n> <expr>)        set nth car of a list
  749.           (aref <expr> <n>)       set nth element of an array
  750.           (get <sym> <prop>)      set value of a property
  751.           (symbol-value <sym>)    set value of a symbol
  752.           (symbol-function <sym>) set functional value of a symbol
  753.           (symbol-plist <sym>)    set property list of a symbol
  754.     <value>     the new value
  755.     returns     the new value
  756.  
  757. (defun <sym> <fargs> <expr>...)  DEFINE A FUNCTION
  758. (defmacro <sym> <fargs> <expr>...)  DEFINE A MACRO
  759.     <sym>       symbol being defined (quoted)
  760.     <fargs>     formal argument list (lambda list) (quoted)
  761.     <expr>      expressions constituting the body of the
  762.         function (quoted)
  763.     returns     the function symbol
  764.  
  765. (gensym [<tag>])  GENERATE A SYMBOL
  766.     <tag>       string or number
  767.     returns     the new symbol
  768.  
  769. (intern <pname>)  MAKE AN INTERNED SYMBOL
  770.     <pname>     the symbol's print name string
  771.     returns     the new symbol
  772.  
  773. (make-symbol <pname>)  MAKE AN UNINTERNED SYMBOL
  774.     <pname>     the symbol's print name string
  775.     returns     the new symbol
  776.  
  777. (symbol-name <sym>)  GET THE PRINT NAME OF A SYMBOL
  778.     <sym>       the symbol
  779.     returns     the symbol's print name
  780.  
  781.  
  782.  
  783.  
  784. XLISP                   SYMBOL FUNCTIONS                 Page 20
  785.  
  786.  
  787. (symbol-value <sym>)  GET THE VALUE OF A SYMBOL
  788.     <sym>       the symbol
  789.     returns     the symbol's value
  790.  
  791. (symbol-function <sym>)  GET THE FUNCTIONAL VALUE OF A SYMBOL
  792.     <sym>       the symbol
  793.     returns     the symbol's functional value
  794.  
  795. (symbol-plist <sym>)  GET THE PROPERTY LIST OF A SYMBOL
  796.     <sym>       the symbol
  797.     returns     the symbol's property list
  798.  
  799. (hash <sym> <n>)  COMPUTE THE HASH INDEX FOR A SYMBOL
  800.     <sym>       the symbol or string
  801.     <n>         the table size (integer)
  802.     returns     the hash index (integer)
  803.  
  804.  
  805.  
  806.  
  807. XLISP               PROPERTY LIST FUNCTIONS              Page 21
  808.  
  809.  
  810. PROPERTY LIST FUNCTIONS
  811.  
  812. (get <sym> <prop>)  GET THE VALUE OF A PROPERTY
  813.     <sym>       the symbol
  814.     <prop>      the property symbol
  815.     returns     the property value or nil
  816.  
  817. (putprop <sym> <val> <prop>)  PUT A PROPERTY ONTO A PROPERTY LIST
  818.     <sym>       the symbol
  819.     <val>       the property value
  820.     <prop>      the property symbol
  821.     returns     the property value
  822.  
  823. (remprop <sym> <prop>)  REMOVE A PROPERTY
  824.     <sym>       the symbol
  825.     <prop>      the property symbol
  826.     returns     nil
  827.  
  828.  
  829.  
  830.  
  831. XLISP                   ARRAY FUNCTIONS                  Page 22
  832.  
  833.  
  834. ARRAY FUNCTIONS
  835.  
  836. (aref <array> <n>)  GET THE NTH ELEMENT OF AN ARRAY
  837.     <array>     the array
  838.     <n>         the array index (integer)
  839.     returns     the value of the array element
  840.  
  841. (make-array <size>)  MAKE A NEW ARRAY
  842.     <size>      the size of the new array (integer)
  843.     returns     the new array
  844.  
  845. (vector <expr>...)  MAKE AN INITIALIZED VECTOR
  846.     <expr>      the vector elements
  847.     returns     the new vector
  848.  
  849.  
  850.  
  851.  
  852. XLISP                    LIST FUNCTIONS                  Page 23
  853.  
  854.  
  855. LIST FUNCTIONS
  856.  
  857. (car <expr>)  RETURN THE CAR OF A LIST NODE
  858.     <expr>      the list node
  859.     returns     the car of the list node
  860.  
  861. (cdr <expr>)  RETURN THE CDR OF A LIST NODE
  862.     <expr>      the list node
  863.     returns     the cdr of the list node
  864.  
  865. (cxxr <expr>)  ALL CxxR COMBINATIONS
  866. (cxxxr <expr>)  ALL CxxxR COMBINATIONS
  867. (cxxxxr <expr>)  ALL CxxxxR COMBINATIONS
  868.  
  869. (first <expr>)   A SYNONYM FOR CAR
  870. (second <expr>)  A SYNONYM FOR CADR
  871. (third <expr>)   A SYNONYM FOR CADDR
  872. (fourth <expr>)  A SYNONYM FOR CADDDR
  873. (rest <expr>)    A SYNONYM FOR CDR
  874.  
  875. (cons <expr1> <expr2>)  CONSTRUCT A NEW LIST NODE
  876.     <expr1>     the car of the new list node
  877.     <expr2>     the cdr of the new list node
  878.     returns     the new list node
  879.  
  880. (list <expr>...)  CREATE A LIST OF VALUES
  881.     <expr>      expressions to be combined into a list
  882.     returns     the new list
  883.  
  884. (append <expr>...)  APPEND LISTS
  885.     <expr>      lists whose elements are to be appended
  886.     returns     the new list
  887.  
  888. (reverse <expr>)  REVERSE A LIST
  889.     <expr>      the list to reverse
  890.     returns     a new list in the reverse order
  891.  
  892. (last <list>)  RETURN THE LAST LIST NODE OF A LIST
  893.     <list>      the list
  894.     returns     the last list node in the list
  895.  
  896. (member <expr> <list> &key :test :test-not)  FIND AN EXPRESSION IN A LIST
  897.     <expr>      the expression to find
  898.     <list>      the list to search
  899.     :test       the test function (defaults to eql)
  900.     :test-not   the test function (sense inverted)    
  901.     returns     the remainder of the list starting with the expression
  902.  
  903. (assoc <expr> <alist> &key :test :test-not)  FIND AN EXPRESSION IN AN A-LIST
  904.     <expr>      the expression to find
  905.     <alist>     the association list
  906.     :test       the test function (defaults to eql)
  907.     :test-not   the test function (sense inverted)    
  908.     returns     the alist entry or nil
  909.  
  910.  
  911.  
  912.  
  913. XLISP                    LIST FUNCTIONS                  Page 24
  914.  
  915.  
  916. (remove <expr> <list> &key :test :test-not)  REMOVE ELEMENTS FROM A LIST
  917.     <expr>      the element to remove
  918.     <list>      the list
  919.     :test       the test function (defaults to eql)
  920.     :test-not   the test function (sense inverted)    
  921.     returns     copy of list with matching expressions removed
  922.  
  923. (remove-if <test> <list>)  REMOVE ELEMENTS THAT PASS TEST
  924.     <test>      the test predicate
  925.     <list>      the list
  926.     returns     copy of list with matching elements removed
  927.  
  928. (remove-if-not <test> <list>)  REMOVE ELEMENTS THAT FAIL TEST
  929.     <test>      the test predicate
  930.     <list>      the list
  931.     returns     copy of list with non-matching elements removed
  932.  
  933. (length <expr>)  FIND THE LENGTH OF A LIST, VECTOR OR STRING
  934.     <expr>      the list, vector or string
  935.     returns     the length of the list, vector or string
  936.  
  937. (nth <n> <list>)  RETURN THE NTH ELEMENT OF A LIST
  938.     <n>         the number of the element to return (zero origin)
  939.     <list>      the list
  940.     returns     the nth element or nil if the list isn't that long
  941.  
  942. (nthcdr <n> <list>)  RETURN THE NTH CDR OF A LIST
  943.     <n>         the number of the element to return (zero origin)
  944.     <list>      the list
  945.     returns     the nth cdr or nil if the list isn't that long
  946.  
  947. (mapc <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CARS
  948.     <fcn>       the function or function name
  949.     <listn>     a list for each argument of the function
  950.     returns     the first list of arguments
  951.  
  952. (mapcar <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CARS
  953.     <fcn>       the function or function name
  954.     <listn>     a list for each argument of the function
  955.     returns     a list of the values returned
  956.  
  957. (mapl <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CDRS
  958.     <fcn>       the function or function name
  959.     <listn>     a list for each argument of the function
  960.     returns     the first list of arguments
  961.  
  962. (maplist <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CDRS
  963.     <fcn>       the function or function name
  964.     <listn>     a list for each argument of the function
  965.     returns     a list of the values returned
  966.  
  967.  
  968.  
  969.  
  970. XLISP                    LIST FUNCTIONS                  Page 25
  971.  
  972.  
  973. (subst <to> <from> <expr> &key :test :test-not)  SUBSTITUTE EXPRESSIONS
  974.     <to>        the new expression
  975.     <from>      the old expression
  976.     <expr>      the expression in which to do the substitutions
  977.     :test       the test function (defaults to eql)
  978.     :test-not   the test function (sense inverted)    
  979.     returns     the expression with substitutions
  980.  
  981. (sublis <alist> <expr> &key :test :test-not)  SUBSTITUTE WITH AN A-LIST
  982.     <alist>     the association list
  983.     <expr>      the expression in which to do the substitutions
  984.     :test       the test function (defaults to eql)
  985.     :test-not   the test function (sense inverted)    
  986.     returns     the expression with substitutions
  987.  
  988.  
  989.  
  990.  
  991. XLISP              DESTRUCTIVE LIST FUNCTIONS            Page 26
  992.  
  993.  
  994. DESTRUCTIVE LIST FUNCTIONS
  995.  
  996. (rplaca <list> <expr>)  REPLACE THE CAR OF A LIST NODE
  997.     <list>      the list node
  998.     <expr>      the new value for the car of the list node
  999.     returns     the list node after updating the car
  1000.  
  1001. (rplacd <list> <expr>)  REPLACE THE CDR OF A LIST NODE
  1002.     <list>      the list node
  1003.     <expr>      the new value for the cdr of the list node
  1004.     returns     the list node after updating the cdr
  1005.  
  1006. (nconc <list>...)  DESTRUCTIVELY CONCATENATE LISTS
  1007.     <list>      lists to concatenate
  1008.     returns     the result of concatenating the lists
  1009.  
  1010. (delete <expr> &key :test :test-not)  DELETE ELEMENTS FROM A LIST
  1011.     <expr>      the element to delete
  1012.     <list>      the list
  1013.     :test       the test function (defaults to eql)
  1014.     :test-not   the test function (sense inverted)    
  1015.     returns     the list with the matching expressions deleted
  1016.  
  1017. (delete-if <test> <list>)  DELETE ELEMENTS THAT PASS TEST
  1018.     <test>      the test predicate
  1019.     <list>      the list
  1020.     returns     the list with matching elements deleted
  1021.  
  1022. (delete-if-not <test> <list>)  DELETE ELEMENTS THAT FAIL TEST
  1023.     <test>      the test predicate
  1024.     <list>      the list
  1025.     returns     the list with non-matching elements deleted
  1026.  
  1027. (sort <list> <test>)  SORT A LIST
  1028.     <list>      the list to sort
  1029.     <test>      the comparison function
  1030.     returns     the sorted list
  1031.  
  1032.  
  1033.  
  1034.  
  1035. XLISP                 PREDICATE FUNCTIONS                Page 27
  1036.  
  1037.  
  1038. PREDICATE FUNCTIONS
  1039.  
  1040. (atom <expr>)  IS THIS AN ATOM?
  1041.     <expr>      the expression to check
  1042.     returns     t if the value is an atom, nil otherwise
  1043.  
  1044. (symbolp <expr>)  IS THIS A SYMBOL?
  1045.     <expr>      the expression to check
  1046.     returns     t if the expression is a symbol, nil otherwise
  1047.  
  1048. (numberp <expr>)  IS THIS A NUMBER?
  1049.     <expr>      the expression to check
  1050.     returns     t if the expression is a number, nil otherwise
  1051.  
  1052. (null <expr>)  IS THIS AN EMPTY LIST?
  1053.     <expr>      the list to check
  1054.     returns     t if the list is empty, nil otherwise
  1055.  
  1056. (not <expr>)  IS THIS FALSE?
  1057.     <expr>      the expression to check
  1058.     return      t if the value is nil, nil otherwise
  1059.  
  1060. (listp <expr>)  IS THIS A LIST?
  1061.     <expr>      the expression to check
  1062.     returns     t if the value is a cons or nil, nil otherwise
  1063.  
  1064. (endp <list>)  IS THIS THE END OF A LIST
  1065.     <list>      the list
  1066.     returns     t if the value is nil, nil otherwise
  1067.  
  1068. (consp <expr>)  IS THIS A NON-EMPTY LIST?
  1069.     <expr>      the expression to check
  1070.     returns     t if the value is a cons, nil otherwise
  1071.  
  1072. (integerp <expr>)  IS THIS AN INTEGER?
  1073.     <expr>      the expression to check
  1074.     returns     t if the value is an integer, nil otherwise
  1075.  
  1076. (floatp <expr>)  IS THIS A FLOAT?
  1077.     <expr>      the expression to check
  1078.     returns     t if the value is a float, nil otherwise
  1079.  
  1080. (stringp <expr>)  IS THIS A STRING?
  1081.     <expr>      the expression to check
  1082.     returns     t if the value is a string, nil otherwise
  1083.  
  1084. (characterp <expr>)  IS THIS A CHARACTER?
  1085.     <expr>      the expression to check
  1086.     returns     t if the value is a character, nil otherwise
  1087.  
  1088. (arrayp <expr>)  IS THIS AN ARRAY?
  1089.     <expr>      the expression to check
  1090.     returns     t if the value is an array, nil otherwise
  1091.  
  1092.  
  1093.  
  1094.  
  1095. XLISP                 PREDICATE FUNCTIONS                Page 28
  1096.  
  1097.  
  1098. (streamp <expr>)  IS THIS A STREAM?
  1099.     <expr>      the expression to check
  1100.     returns     t if the value is a stream, nil otherwise
  1101.  
  1102. (objectp <expr>)  IS THIS AN OBJECT?
  1103.     <expr>      the expression to check
  1104.     returns     t if the value is an object, nil otherwise
  1105.  
  1106. (boundp <sym>)  IS A VALUE BOUND TO THIS SYMBOL?
  1107.     <sym>       the symbol
  1108.     returns     t if a value is bound to the symbol, nil otherwise
  1109.  
  1110. (fboundp <sym>)  IS A FUNCTIONAL VALUE BOUND TO THIS SYMBOL?
  1111.     <sym>       the symbol
  1112.     returns     t if a functional value is bound to the symbol,
  1113.         nil otherwise
  1114.  
  1115. (minusp <expr>)  IS THIS NUMBER NEGATIVE?
  1116.     <expr>      the number to test
  1117.     returns     t if the number is negative, nil otherwise
  1118.  
  1119. (zerop <expr>)  IS THIS NUMBER ZERO?
  1120.     <expr>      the number to test
  1121.     returns     t if the number is zero, nil otherwise
  1122.  
  1123. (plusp <expr>)  IS THIS NUMBER POSITIVE?
  1124.     <expr>      the number to test
  1125.     returns     t if the number is positive, nil otherwise
  1126.  
  1127. (evenp <expr>)  IS THIS INTEGER EVEN?
  1128.     <expr>      the integer to test
  1129.     returns     t if the integer is even, nil otherwise
  1130.  
  1131. (oddp <expr>)  IS THIS INTEGER ODD?
  1132.     <expr>      the integer to test
  1133.     returns     t if the integer is odd, nil otherwise
  1134.  
  1135. (eq <expr1> <expr2>)  ARE THE EXPRESSIONS IDENTICAL?
  1136.     <expr1>     the first expression
  1137.     <expr2>     the second expression
  1138.     returns     t if they are equal, nil otherwise
  1139.  
  1140. (eql <expr1> <expr2>)  ARE THE EXPRESSIONS IDENTICAL?
  1141.             (WORKS WITH ALL NUMBERS)
  1142.     <expr1>     the first expression
  1143.     <expr2>     the second expression
  1144.     returns     t if they are equal, nil otherwise
  1145.  
  1146. (equal <expr1> <expr2>)  ARE THE EXPRESSIONS EQUAL?
  1147.     <expr1>     the first expression
  1148.     <expr2>     the second expression
  1149.     returns     t if they are equal, nil otherwise
  1150.  
  1151.  
  1152.  
  1153.  
  1154. XLISP                  CONTROL CONSTRUCTS                Page 29
  1155.  
  1156.  
  1157. CONTROL CONSTRUCTS
  1158.  
  1159. (cond <pair>...)  EVALUATE CONDITIONALLY
  1160.     <pair>      pair consisting of:
  1161.             (<pred> <expr>...)
  1162.           where
  1163.             <pred>      is a predicate expression
  1164.             <expr>      evaluated if the predicate
  1165.                 is not nil
  1166.     returns     the value of the first expression whose predicate
  1167.         is not nil
  1168.  
  1169. (and <expr>...)  THE LOGICAL AND OF A LIST OF EXPRESSIONS
  1170.     <expr>      the expressions to be ANDed
  1171.     returns     nil if any expression evaluates to nil,
  1172.         otherwise the value of the last expression
  1173.         (evaluation of expressions stops after the first
  1174.          expression that evaluates to nil)
  1175.  
  1176. (or <expr>...)  THE LOGICAL OR OF A LIST OF EXPRESSIONS
  1177.     <expr>      the expressions to be ORed
  1178.     returns     nil if all expressions evaluate to nil,
  1179.         otherwise the value of the first non-nil expression
  1180.         (evaluation of expressions stops after the first
  1181.          expression that does not evaluate to nil)
  1182.  
  1183. (if <texpr> <expr1> [<expr2>])  EVALUATE EXPRESSIONS CONDITIONALLY
  1184.     <texpr>     the test expression
  1185.     <expr1>     the expression to be evaluated if texpr is non-nil
  1186.     <expr2>     the expression to be evaluated if texpr is nil
  1187.     returns     the value of the selected expression
  1188.  
  1189. (when <texpr> <expr>...)  EVALUATE ONLY WHEN A CONDITION IS TRUE
  1190.     <texpr>     the test expression
  1191.     <expr>      the expression(s) to be evaluted if texpr is non-nil
  1192.     returns     the value of the last expression or nil
  1193.  
  1194. (unless <texpr> <expr>...)  EVALUATE ONLY WHEN A CONDITION IS FALSE
  1195.     <texpr>     the test expression
  1196.     <expr>      the expression(s) to be evaluated if texpr is nil
  1197.     returns     the value of the last expression or nil
  1198.  
  1199.   (case <expr> <case>...)  SELECT BY CASE
  1200.     <expr>      the selection expression
  1201.     <case>      pair consisting of:
  1202.             (<value> <expr>...)
  1203.           where:
  1204.             <value>     is a single expression or a list of
  1205.                 expressions (unevaluated)
  1206.             <expr>      are expressions to execute if the
  1207.                 case matches
  1208.     returns     the value of the last expression of the matching case
  1209.  
  1210.  
  1211.  
  1212.  
  1213. XLISP                  CONTROL CONSTRUCTS                Page 30
  1214.  
  1215.  
  1216. (let (<binding>...) <expr>...)  CREATE LOCAL BINDINGS
  1217. (let* (<binding>...) <expr>...)  LET WITH SEQUENTIAL BINDING
  1218.     <binding>   the variable bindings each of which is either:
  1219.         1)  a symbol (which is initialized to nil)
  1220.         2)  a list whose car is a symbol and whose cadr
  1221.             is an initialization expression
  1222.     <expr>      the expressions to be evaluated
  1223.     returns     the value of the last expression
  1224.  
  1225. (flet (<binding>...) <expr>...)  CREATE LOCAL FUNCTIONS
  1226. (labels (<binding>...) <expr>...)  FLET WITH RECURSIVE FUNCTIONS
  1227. (macrolet (<binding>...) <expr>...)  CREATE LOCAL MACROS
  1228.     <binding>   the function bindings each of which is:
  1229.           (<sym> <fargs> <expr>...)
  1230.         where:
  1231.             <sym>       the function/macro name
  1232.             <fargs>     formal argument list (lambda list)
  1233.             <expr>      expressions constituting the body of
  1234.                 the function/macro
  1235.     <expr>      the expressions to be evaluated
  1236.     returns     the value of the last expression
  1237.  
  1238. (catch <sym> <expr>...)  EVALUATE EXPRESSIONS AND CATCH THROWS
  1239.     <sym>       the catch tag
  1240.     <expr>      expressions to evaluate
  1241.     returns     the value of the last expression the throw expression
  1242.  
  1243. (throw <sym> [<expr>])  THROW TO A CATCH
  1244.     <sym>       the catch tag
  1245.     <expr>      the value for the catch to return (defaults to nil)
  1246.     returns     never returns
  1247.  
  1248. (unwind-protect <expr> <cexpr>...)  PROTECT EVALUATION OF AN EXPRESSION
  1249.     <expr>      the expression to protect
  1250.     <cexpr>     the cleanup expressions
  1251.     returns     the value of the expression
  1252.   Note:  unwind-protect guarantees to execute the cleanup expressions
  1253.      even if a non-local exit terminates the evaluation of the
  1254.      protected expression
  1255.  
  1256.  
  1257.  
  1258.  
  1259. XLISP                  LOOPING CONSTRUCTS                Page 31
  1260.  
  1261.  
  1262. LOOPING CONSTRUCTS
  1263.  
  1264. (loop <expr>...)  BASIC LOOPING FORM
  1265.     <expr>      the body of the loop
  1266.     returns     never returns (must use non-local exit)
  1267.  
  1268. (do (<binding>...) (<texpr> <rexpr>...) <expr>...)
  1269. (do* (<binding>...) (<texpr> <rexpr>...) <expr>...)
  1270.     <binding>   the variable bindings each of which is either:
  1271.         1)  a symbol (which is initialized to nil)
  1272.         2)  a list of the form: (<sym> <init> [<step>])
  1273.             where:
  1274.             <sym>  is the symbol to bind
  1275.             <init> is the initial value of the symbol
  1276.             <step> is a step expression
  1277.     <texpr>     the termination test expression
  1278.     <rexpr>     result expressions (the default is nil)
  1279.     <expr>      the body of the loop (treated like an implicit prog)
  1280.     returns     the value of the last result expression
  1281.  
  1282. (dolist (<sym> <expr> [<rexpr>]) <expr>...)  LOOP THROUGH A LIST
  1283.     <sym>       the symbol to bind to each list element
  1284.     <expr>      the list expression
  1285.     <rexpr>     the result expression (the default is nil)
  1286.     <expr>      the body of the loop (treated like an implicit prog)
  1287.  
  1288. (dotimes (<sym> <expr> [<rexpr>]) <expr>...)  LOOP FROM ZERO TO N-1
  1289.     <sym>       the symbol to bind to each value from 0 to n-1
  1290.     <expr>      the number of times to loop
  1291.     <rexpr>     the result expression (the default is nil)
  1292.     <expr>      the body of the loop (treated like an implicit prog)
  1293.  
  1294.  
  1295.  
  1296.  
  1297. XLISP                 THE PROGRAM FEATURE                Page 32
  1298.  
  1299.  
  1300. THE PROGRAM FEATURE
  1301.  
  1302. (prog (<binding>...) <expr>...)  THE PROGRAM FEATURE
  1303. (prog* (<binding>...) <expr>...)  PROG WITH SEQUENTIAL BINDING
  1304.     <binding>   the variable bindings each of which is either:
  1305.         1)  a symbol (which is initialized to nil)
  1306.         2)  a list whose car is a symbol and whose cadr
  1307.             is an initialization expression
  1308.     <expr>      expressions to evaluate or tags (symbols)
  1309.     returns     nil or the argument passed to the return function
  1310.  
  1311. (block <name> <expr>...)  NAMED BLOCK
  1312.     <name>      the block name (symbol)
  1313.     <expr>      the block body
  1314.     returns     the value of the last expression
  1315.  
  1316. (return [<expr>])  CAUSE A PROG CONSTRUCT TO RETURN A VALUE
  1317.     <expr>      the value (defaults to nil)
  1318.     returns     never returns
  1319.  
  1320. (return-from <name> [<value>])  RETURN FROM A NAMED BLOCK
  1321.     <name>      the block name (symbol)
  1322.     <value>     the value to return (defaults to nil)
  1323.     returns     never returns
  1324.  
  1325. (tagbody <expr>...)  BLOCK WITH LABELS
  1326.     <expr>      expression(s) to evaluate or tags (symbols)
  1327.     returns     nil
  1328.  
  1329. (go <sym>)  GO TO A TAG WITHIN A TAGBODY OR PROG
  1330.     <sym>       the tag (quoted)
  1331.     returns     never returns
  1332.  
  1333. (progv <slist> <vlist> <expr>...)  DYNAMICALLY BIND SYMBOLS
  1334.     <slist>     list of symbols
  1335.     <vlist>     list of values to bind to the symbols
  1336.     <expr>      expression(s) to evaluate
  1337.     returns     the value of the last expression
  1338.  
  1339. (prog1 <expr1> <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  1340.     <expr1>     the first expression to evaluate
  1341.     <expr>      the remaining expressions to evaluate
  1342.     returns     the value of the first expression
  1343.  
  1344. (prog2 <expr1> <expr2> <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  1345.     <expr1>     the first expression to evaluate
  1346.     <expr2>     the second expression to evaluate
  1347.     <expr>      the remaining expressions to evaluate
  1348.     returns     the value of the second expression
  1349.  
  1350. (progn <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  1351.     <expr>      the expressions to evaluate
  1352.     returns     the value of the last expression (or nil)
  1353.  
  1354.  
  1355.  
  1356.  
  1357. XLISP             DEBUGGING AND ERROR HANDLING           Page 33
  1358.  
  1359.  
  1360. DEBUGGING AND ERROR HANDLING
  1361.  
  1362. (trace <sym>)  ADD A FUNCTION TO THE TRACE LIST
  1363.     <sym>       the function to add (quoted)
  1364.     returns     the trace list
  1365.  
  1366. (untrace <sym>)  REMOVE A FUNCTION FROM THE TRACE LIST
  1367.     <sym>       the function to remove (quoted)
  1368.     returns     the trace list
  1369.  
  1370. (error <emsg> [<arg>])  SIGNAL A NON-CORRECTABLE ERROR
  1371.     <emsg>      the error message string
  1372.     <arg>       the argument expression (printed after the message)
  1373.     returns     never returns
  1374.  
  1375. (cerror <cmsg> <emsg> [<arg>])  SIGNAL A CORRECTABLE ERROR
  1376.     <cmsg>      the continue message string
  1377.     <emsg>      the error message string
  1378.     <arg>       the argument expression (printed after the message)
  1379.     returns     nil when continued from the break loop
  1380.  
  1381. (break [<bmsg> [<arg>]])  ENTER A BREAK LOOP
  1382.     <bmsg>      the break message string (defaults to "**BREAK**")
  1383.     <arg>       the argument expression (printed after the message)
  1384.     returns     nil when continued from the break loop
  1385.  
  1386. (clean-up)  CLEAN-UP AFTER AN ERROR
  1387.     returns     never returns
  1388.  
  1389. (top-level)  CLEAN-UP AFTER AN ERROR AND RETURN TO THE TOP LEVEL
  1390.     returns     never returns
  1391.  
  1392. (continue)  CONTINUE FROM A CORRECTABLE ERROR
  1393.     returns     never returns
  1394.  
  1395. (errset <expr> [<pflag>])  TRAP ERRORS
  1396.     <expr>      the expression to execute
  1397.     <pflag>     flag to control printing of the error message
  1398.     returns     the value of the last expression consed with nil
  1399.         or nil on error
  1400.  
  1401. (baktrace [<n>])  PRINT N LEVELS OF TRACE BACK INFORMATION
  1402.     <n>         the number of levels (defaults to all levels)
  1403.     returns     nil
  1404.  
  1405. (evalhook <expr> <ehook> <ahook> [<env>])  EVALUATE WITH HOOKS
  1406.     <expr>      the expression to evaluate
  1407.     <ehook>     the value for *evalhook*
  1408.     <ahook>     the value for *applyhook*
  1409.     <env>       the environment (default is nil)
  1410.     returns     the result of evaluating the expression
  1411.  
  1412.  
  1413.  
  1414.  
  1415. XLISP                 ARITHMETIC FUNCTIONS               Page 34
  1416.  
  1417.  
  1418. ARITHMETIC FUNCTIONS
  1419.  
  1420. (truncate <expr>)  TRUNCATES A FLOATING POINT NUMBER TO AN INTEGER
  1421.     <expr>      the number
  1422.     returns     the result of truncating the number
  1423.  
  1424. (float <expr>)  CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
  1425.     <expr>      the number
  1426.     returns     the result of floating the integer
  1427.  
  1428. (+ <expr>...)  ADD A LIST OF NUMBERS
  1429.     <expr>      the numbers
  1430.     returns     the result of the addition
  1431.  
  1432. (- <expr>...)  SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
  1433.     <expr>      the numbers
  1434.     returns     the result of the subtraction
  1435.  
  1436. (* <expr>...)  MULTIPLY A LIST OF NUMBERS
  1437.     <expr>      the numbers
  1438.     returns     the result of the multiplication
  1439.  
  1440. (/ <expr>...)  DIVIDE A LIST OF NUMBERS
  1441.     <expr>      the numbers
  1442.     returns     the result of the division
  1443.  
  1444. (1+ <expr>)  ADD ONE TO A NUMBER
  1445.     <expr>      the number
  1446.     returns     the number plus one
  1447.  
  1448. (1- <expr>)  SUBTRACT ONE FROM A NUMBER
  1449.     <expr>      the number
  1450.     returns     the number minus one
  1451.  
  1452. (rem <expr>...)  REMAINDER OF A LIST OF NUMBERS
  1453.     <expr>      the numbers
  1454.     returns     the result of the remainder operation
  1455.  
  1456. (min <expr>...)  THE SMALLEST OF A LIST OF NUMBERS
  1457.     <expr>      the expressions to be checked
  1458.     returns     the smallest number in the list
  1459.  
  1460. (max <expr>...)  THE LARGEST OF A LIST OF NUMBERS
  1461.     <expr>      the expressions to be checked
  1462.     returns     the largest number in the list
  1463.  
  1464. (abs <expr>)  THE ABSOLUTE VALUE OF A NUMBER
  1465.     <expr>      the number
  1466.     returns     the absolute value of the number
  1467.  
  1468. (gcd <n1> <n2>...)  COMPUTE THE GREATEST COMMON DIVISOR
  1469.     <n1>        the first number (integer)
  1470.     <n2>        the second number(s) (integer)
  1471.     returns     the greatest common divisor
  1472.  
  1473.  
  1474.  
  1475.  
  1476. XLISP                 ARITHMETIC FUNCTIONS               Page 35
  1477.  
  1478.  
  1479. (random <n>)  COMPUTE A RANDOM NUMBER BETWEEN 1 and N-1
  1480.     <n>         the upper bound (integer)
  1481.     returns     a random number
  1482.  
  1483. (sin <expr>)  COMPUTE THE SINE OF A NUMBER
  1484.     <expr>      the floating point number
  1485.     returns     the sine of the number
  1486.  
  1487. (cos <expr>)  COMPUTE THE COSINE OF A NUMBER
  1488.     <expr>      the floating point number
  1489.     returns     the cosine of the number
  1490.  
  1491. (tan <expr>)  COMPUTE THE TANGENT OF A NUMBER
  1492.     <expr>      the floating point number
  1493.     returns     the tangent of the number
  1494.  
  1495. (expt <x-expr> <y-expr>)  COMPUTE X TO THE Y POWER
  1496.     <x-expr>    the floating point number
  1497.     <y-expr>    the floating point exponent
  1498.     returns     x to the y power
  1499.  
  1500. (exp <x-expr>)  COMPUTE E TO THE X POWER
  1501.     <x-expr>    the floating point number
  1502.     returns     e to the x power
  1503.  
  1504. (sqrt <expr>)  COMPUTE THE SQUARE ROOT OF A NUMBER
  1505.     <expr>      the floating point number
  1506.     returns     the square root of the number
  1507.  
  1508. (< <n1> <n2>...)  TEST FOR LESS THAN
  1509. (<= <n1> <n2>...)  TEST FOR LESS THAN OR EQUAL TO
  1510. (= <n1> <n2>...)  TEST FOR EQUAL TO
  1511. (/= <n1> <n2>...)  TEST FOR NOT EQUAL TO
  1512. (>= <n1> <n2>...)  TEST FOR GREATER THAN OR EQUAL TO
  1513. (> <n1> <n2>...)  TEST FOR GREATER THAN
  1514.     <n1>        the first number to compare
  1515.     <n2>        the second number to compare
  1516.     returns     the result of comparing <n1> with <n2>...
  1517.  
  1518.  
  1519.  
  1520.  
  1521. XLISP              BITWISE LOGICAL FUNCTIONS             Page 36
  1522.  
  1523.  
  1524. BITWISE LOGICAL FUNCTIONS
  1525.  
  1526. (logand <expr>...)  THE BITWISE AND OF A LIST OF NUMBERS
  1527.     <expr>      the numbers
  1528.     returns     the result of the and operation
  1529.  
  1530. (logior <expr>...)  THE BITWISE INCLUSIVE OR OF A LIST OF NUMBERS
  1531.     <expr>      the numbers
  1532.     returns     the result of the inclusive or operation
  1533.  
  1534. (logxor <expr>...)  THE BITWISE EXCLUSIVE OR OF A LIST OF NUMBERS
  1535.     <expr>      the numbers
  1536.     returns     the result of the exclusive or operation
  1537.  
  1538. (lognot <expr>)  THE BITWISE NOT OF A NUMBER
  1539.     <expr>      the number
  1540.     returns     the bitwise inversion of number
  1541.  
  1542.  
  1543.  
  1544.  
  1545. XLISP                   STRING FUNCTIONS                 Page 37
  1546.  
  1547.  
  1548. STRING FUNCTIONS
  1549.  
  1550. (string <expr>)  MAKE A STRING FROM AN INTEGER ASCII VALUE
  1551.     <expr>      the integer
  1552.     returns     a one character string
  1553.  
  1554. (string-trim <bag> <str>)  TRIM BOTH ENDS OF A STRING
  1555.     <bag>       a string containing characters to trim
  1556.     <str>       the string to trim
  1557.     returns     a trimed copy of the string
  1558.  
  1559. (string-left-trim <bag> <str>)  TRIM THE LEFT END OF A STRING
  1560.     <bag>       a string containing characters to trim
  1561.     <str>       the string to trim
  1562.     returns     a trimed copy of the string
  1563.  
  1564. (string-right-trim <bag> <str>)  TRIM THE RIGHT END OF A STRING
  1565.     <bag>       a string containing characters to trim
  1566.     <str>       the string to trim
  1567.     returns     a trimed copy of the string
  1568.  
  1569. (string-upcase <str> &key :start :end)  CONVERT TO UPPERCASE
  1570.     <str>       the string
  1571.     :start      the starting offset
  1572.     :end        the ending offset + 1
  1573.     returns     a converted copy of the string
  1574.  
  1575. (string-downcase <str> &key :start :end)  CONVERT TO LOWERCASE
  1576.     <str>       the string
  1577.     :start      the starting offset
  1578.     :end        the ending offset + 1
  1579.     returns     a converted copy of the string
  1580.  
  1581. (nstring-upcase <str> &key :start :end)  CONVERT TO UPPERCASE
  1582.     <str>       the string
  1583.     :start      the starting offset
  1584.     :end        the ending offset + 1
  1585.     returns     the converted string (not a copy)
  1586.  
  1587. (nstring-downcase <str> &key :start :end)  CONVERT TO LOWERCASE
  1588.     <str>       the string
  1589.     :start      the starting offset
  1590.     :end        the ending offset + 1
  1591.     returns     the converted string (not a copy)
  1592.  
  1593. (strcat <expr>...)  CONCATENATE STRINGS
  1594.     <expr>      the strings to concatenate
  1595.     returns     the result of concatenating the strings
  1596.  
  1597. (subseq <string> <start> [<end>]) EXTRACT A SUBSTRING
  1598.     <string>    the string
  1599.     <start>     the starting position (zero origin)
  1600.     <end>       the ending position + 1 (defaults to end)
  1601.     returns     substring between <start> and <end>
  1602.  
  1603.  
  1604.  
  1605.  
  1606. XLISP                   STRING FUNCTIONS                 Page 38
  1607.  
  1608.  
  1609. (string< <str1> <str2> &key :start1 :end1 :start2 :end2)
  1610. (string<= <str1> <str2> &key :start1 :end1 :start2 :end2)
  1611. (string= <str1> <str2> &key :start1 :end1 :start2 :end2)
  1612. (string/= <str1> <str2> &key :start1 :end1 :start2 :end2)
  1613. (string>= <str1> <str2> &key :start1 :end1 :start2 :end2)
  1614. (string> <str1> <str2> &key :start1 :end1 :start2 :end2)
  1615.     <str1>      the first string to compare
  1616.     <str2>      the second string to compare
  1617.     :start1     first substring starting offset
  1618.     :end1       first substring ending offset + 1
  1619.     :start2     second substring starting offset
  1620.     :end2       second substring ending offset + 1
  1621.     returns     t if predicate is true, nil otherwise
  1622.   Note: case is significant with these comparison functions.
  1623.  
  1624. (string-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
  1625. (string-not-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
  1626. (string-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
  1627. (string-not-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
  1628. (string-not-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
  1629. (string-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
  1630.     <str1>      the first string to compare
  1631.     <str2>      the second string to compare
  1632.     :start1     first substring starting offset
  1633.     :end1       first substring ending offset + 1
  1634.     :start2     second substring starting offset
  1635.     :end2       second substring ending offset + 1
  1636.     returns     t if predicate is true, nil otherwise
  1637.   Note: case is not significant with these comparison functions.
  1638.  
  1639.  
  1640.  
  1641.  
  1642. XLISP                 CHARACTER FUNCTIONS                Page 39
  1643.  
  1644.  
  1645. CHARACTER FUNCTIONS
  1646.  
  1647. (char <string> <index>)  EXTRACT A CHARACTER FROM A STRING
  1648.     <string>    the string
  1649.     <index>     the string index (zero relative)
  1650.     returns     the ascii code of the character
  1651.  
  1652. (upper-case-p <chr>)  IS THIS AN UPPER CASE CHARACTER?
  1653.     <chr>       the character
  1654.     returns     true if the character is upper case, nil otherwise
  1655.  
  1656. (lower-case-p <chr>)  IS THIS A LOWER CASE CHARACTER?
  1657.     <chr>       the character
  1658.     returns     true if the character is lower case, nil otherwise
  1659.  
  1660. (both-case-p <chr>)  IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER?
  1661.     <chr>       the character
  1662.     returns     true if the character is alphabetic, nil otherwise
  1663.  
  1664. (digit-char-p <chr>)  IS THIS A DIGIT CHARACTER?
  1665.     <chr>       the character
  1666.     returns     the digit weight if character is a digit, nil otherwise
  1667.  
  1668. (char-code <chr>)  GET THE ASCII CODE OF A CHARACTER
  1669.     <chr>       the character
  1670.     returns     the ASCII character code (integer)
  1671.  
  1672. (code-char <code>)  GET THE CHARACTER WITH A SPECFIED ASCII CODE
  1673.     <code>      the ASCII code (integer)
  1674.     returns     the character with that code or nil
  1675.  
  1676. (char-upcase <chr>)  CONVERT A CHARACTER TO UPPER CASE
  1677.     <chr>       the character
  1678.     returns     the upper case character
  1679.  
  1680. (char-downcase <chr>)  CONVERT A CHARACTER TO LOWER CASE
  1681.     <chr>       the character
  1682.     returns     the lower case character
  1683.  
  1684. (digit-char <n>)  CONVERT A DIGIT WEIGHT TO A DIGIT
  1685.     <n>         the digit weight (integer)
  1686.     returns     the digit character or nil
  1687.  
  1688. (char-int <chr>) CONVERT A CHARACTER TO AN INTEGER
  1689.     <chr>       the character
  1690.     returns     the ASCII character code
  1691.  
  1692. (int-char <int>) CONVERT AN INTEGER TO A CHARACTER
  1693.     <int>       the ASCII character code
  1694.     returns     the character with that code
  1695.  
  1696.  
  1697.  
  1698.  
  1699. XLISP                 CHARACTER FUNCTIONS                Page 40
  1700.  
  1701.  
  1702. (char< <chr1> <chr2>...)
  1703. (char<= <chr1> <chr2>...)
  1704. (char= <chr1> <chr2>...)
  1705. (char/= <chr1> <chr2>...)
  1706. (char>= <chr1> <chr2>...)
  1707. (char> <chr1> <chr2>...)
  1708.     <chr1>      the first character to compare
  1709.     <chr2>      the second character(s) to compare
  1710.     returns     t if predicate is true, nil otherwise
  1711.   Note: case is significant with these comparison functions.
  1712.  
  1713. (char-lessp <chr1> <chr2>...)
  1714. (char-not-greaterp <chr1> <chr2>...)
  1715. (char-equalp <chr1> <chr2>...)
  1716. (char-not-equalp <chr1> <chr2>...)
  1717. (char-not-lessp <chr1> <chr2>...)
  1718. (char-greaterp <chr1> <chr2>...)
  1719.     <chr1>      the first string to compare
  1720.     <chr2>      the second string(s) to compare
  1721.     returns     t if predicate is true, nil otherwise
  1722.   Note: case is not significant with these comparison functions.
  1723.  
  1724.  
  1725.  
  1726.  
  1727. XLISP                INPUT/OUTPUT FUNCTIONS              Page 41
  1728.  
  1729.  
  1730. INPUT/OUTPUT FUNCTIONS
  1731.  
  1732. (read [<stream> [<eof> [<rflag>]]])  READ AN EXPRESSION
  1733.     <stream>    the input stream (default is standard input)
  1734.     <eof>       the value to return on end of file (default is nil)
  1735.     <rflag>     recursive read flag (default is nil)
  1736.     returns     the expression read
  1737.  
  1738. (print <expr> [<stream>])  PRINT AN EXPRESSION ON A NEW LINE
  1739.     <expr>      the expression to be printed
  1740.     <stream>    the output stream (default is standard output)
  1741.     returns     the expression
  1742.  
  1743. (prin1 <expr> [<stream>])  PRINT AN EXPRESSION
  1744.     <expr>      the expression to be printed
  1745.     <stream>    the output stream (default is standard output)
  1746.     returns     the expression
  1747.  
  1748. (princ <expr> [<stream>])  PRINT AN EXPRESSION WITHOUT QUOTING
  1749.     <expr>      the expressions to be printed
  1750.     <stream>    the output stream (default is standard output)
  1751.     returns     the expression
  1752.  
  1753. (pprint <expr> [<stream>])  PRETTY PRINT AN EXPRESSION
  1754.     <expr>      the expressions to be printed
  1755.     <stream>    the output stream (default is standard output)
  1756.     returns     the expression
  1757.  
  1758. (terpri [<stream>])  TERMINATE THE CURRENT PRINT LINE
  1759.     <stream>    the output stream (default is standard output)
  1760.     returns     nil
  1761.  
  1762. (flatsize <expr>)  LENGTH OF PRINTED REPRESENTATION USING PRIN1
  1763.     <expr>      the expression
  1764.     returns     the length
  1765.  
  1766. (flatc <expr>)  LENGTH OF PRINTED REPRESENTATION USING PRINC
  1767.     <expr>      the expression
  1768.     returns     the length
  1769.  
  1770.  
  1771.  
  1772.  
  1773. XLISP                 THE FORMAT FUNCTION                Page 42
  1774.  
  1775.  
  1776. THE FORMAT FUNCTION
  1777.  
  1778. (format <stream> <fmt> <arg>...)  DO FORMATTED OUTPUT
  1779.     <stream>    the output stream
  1780.     <fmt>       the format string
  1781.     <arg>       the format arguments
  1782.     returns     output string if <stream> is nil, nil otherwise
  1783.  
  1784. The format string can contain characters that should be copied
  1785. directly to the output and formatting directives.  The
  1786. formatting directives are:
  1787.  
  1788.     ~A          print next argument using princ
  1789.     ~S          print next argument using prin1
  1790.     ~%          start a new line
  1791.     ~~          print a tilde character
  1792.  
  1793.  
  1794.  
  1795.  
  1796. XLISP                  FILE I/O FUNCTIONS                Page 43
  1797.  
  1798.  
  1799. FILE I/O FUNCTIONS
  1800.  
  1801. (open <fname> &key :direction)  OPEN A FILE STREAM
  1802.     <fname>     the file name string or symbol
  1803.     :direction  :input or :output (default is :input)
  1804.     returns     a stream
  1805.  
  1806. (close <stream>)  CLOSE A FILE STREAM
  1807.     <stream>    the stream
  1808.     returns     nil
  1809.  
  1810. (read-char [<stream>])  READ A CHARACTER FROM A STREAM
  1811.     <stream>    the input stream (default is standard input)
  1812.     returns     the character
  1813.  
  1814. (peek-char [<flag> [<stream>]])  PEEK AT THE NEXT CHARACTER
  1815.     <flag>      flag for skipping white space (default is nil)
  1816.     <stream>    the input stream (default is standard input)
  1817.     returns     the character (integer)
  1818.  
  1819. (write-char <ch> [<stream>])  WRITE A CHARACTER TO A STREAM
  1820.     <ch>        the character to write
  1821.     <stream>    the output stream (default is standard output)
  1822.     returns     the character
  1823.  
  1824. (read-line [<stream>])  READ A LINE FROM A STREAM
  1825.     <stream>    the input stream (default is standard input)
  1826.     returns     the string
  1827.  
  1828. (read-byte [<stream>])  READ A BYTE FROM A STREAM
  1829.     <stream>    the input stream (default is standard input)
  1830.     returns     the byte (integer)
  1831.  
  1832. (write-byte <byte> [<stream>])  WRITE A BYTE TO A STREAM
  1833.     <byte>      the byte to write (integer)
  1834.     <stream>    the output stream (default is standard output)
  1835.     returns     the byte (integer)
  1836.  
  1837.  
  1838.  
  1839.  
  1840. XLISP               STRING STREAM FUNCTIONS              Page 44
  1841.  
  1842.  
  1843. STRING STREAM FUNCTIONS
  1844.  
  1845. These functions operate on unnamed streams.  An unnamed output
  1846. stream collects characters sent to it when it is used as the
  1847. destination of any output function.  The functions 'get-output-
  1848. stream-string' and string or a list of characters.
  1849.  
  1850. An unnamed input stream is setup with the 'make-string-input-
  1851. stream' function and returns each character of the string when
  1852. it is used as the source of any input function.
  1853.  
  1854. (make-string-input-stream <str> [<start> [<end>]])
  1855.     <str>       the string
  1856.     <start>     the starting offset
  1857.     <end>       the ending offset + 1
  1858.     returns     an unnamed stream that reads from the string
  1859.  
  1860. (make-string-output-stream)
  1861.     returns     an unnamed output stream
  1862.  
  1863. (get-output-stream-string <stream>)
  1864.     <stream>    the output stream
  1865.     returns     the output so far as a string
  1866.   Note:  the output stream is emptied by this function
  1867.  
  1868. (get-output-stream-list <stream>)
  1869.     <stream>    the output stream
  1870.     returns     the output so far as a list
  1871.   Note:  the output stream is emptied by this function
  1872.  
  1873.  
  1874.  
  1875.  
  1876. XLISP                   SYSTEM FUNCTIONS                 Page 45
  1877.  
  1878.  
  1879. SYSTEM FUNCTIONS
  1880.  
  1881. (load <fname> &key :verbose :print)  LOAD A SOURCE FILE
  1882.     <fname>     the filename string or symbol
  1883.     :verbose    the verbose flag (default is t)
  1884.     :print      the print flag (default is nil)
  1885.     returns     the filename
  1886.  
  1887. (save <fname>) SAVE WORKSPACE TO A FILE
  1888.     <fname>     the filename string or symbol
  1889.     returns     t if workspace was written, nil otherwise
  1890.  
  1891. (restore <fname>) RESTORE WORKSPACE FROM A FILE
  1892.     <fname>     the filename string or symbol
  1893.     returns     nil on failure, otherwise never returns
  1894.  
  1895. (dribble [<fname>])  CREATE A FILE WITH A TRANSCRIPT OF A SESSION
  1896.     <fname>     file name string or symbol
  1897.         (if missing, close current transcript)
  1898.     returns     t if the transcript is opened, nil if it is closed
  1899.  
  1900. (gc)  FORCE GARBAGE COLLECTION
  1901.     returns     nil
  1902.  
  1903. (expand <num>)  EXPAND MEMORY BY ADDING SEGMENTS
  1904.     <num>       the number of segments to add
  1905.     returns     the number of segments added
  1906.  
  1907. (alloc <num>)  CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT
  1908.     <num>       the number of nodes to allocate
  1909.     returns     the old number of nodes to allocate
  1910.  
  1911. (room)  SHOW MEMORY ALLOCATION STATISTICS
  1912.     returns     nil
  1913.  
  1914. (type-of <expr>)  RETURNS THE TYPE OF THE EXPRESSION
  1915.     <expr>      the expression to return the type of
  1916.     returns     nil if the value is nil otherwise one of the symbols:
  1917.           SYMBOL          for symbols
  1918.           OBJECT          for objects
  1919.           CONS            for conses
  1920.           SUBR            for built-in functions
  1921.           FSUBR           for special forms
  1922.           CLOSURE         for defined functions
  1923.           STRING          for strings
  1924.           FIXNUM          for integers
  1925.           FLONUM          for floating point numbers
  1926.           CHARACTER       for characters
  1927.           FILE-STREAM     for file pointers
  1928.           UNNAMED-STREAM  for unnamed streams
  1929.           ARRAY           for arrays
  1930.  
  1931.  
  1932.  
  1933.  
  1934. XLISP                   SYSTEM FUNCTIONS                 Page 46
  1935.  
  1936.  
  1937. (peek <addrs>)  PEEK AT A LOCATION IN MEMORY
  1938.     <addrs>     the address to peek at (integer)
  1939.     returns     the value at the specified address (integer)
  1940.  
  1941. (poke <addrs> <value>)  POKE A VALUE INTO MEMORY
  1942.     <addrs>     the address to poke (integer)
  1943.     <value>     the value to poke into the address (integer)
  1944.     returns     the value
  1945.  
  1946. (address-of <expr>)  GET THE ADDRESS OF AN XLISP NODE
  1947.     <expr>      the node
  1948.     returns     the address of the node (integer)
  1949.  
  1950. (exit)  EXIT XLISP
  1951.     returns     never returns
  1952.  
  1953.  
  1954.  
  1955.  
  1956. XLISP                       EXAMPLES                     Page 47
  1957.  
  1958.  
  1959. FILE I/O FUNCTIONS
  1960.  
  1961. Input from a File
  1962.  
  1963. To open a file for input, use the OPEN function with the keyword
  1964. argument :DIRECTION set to :INPUT.  To open a file for output,
  1965. use the OPEN function with the keyword argument :DIRECTION set
  1966. to :OUTPUT.  The OPEN function takes a single required argument
  1967. which is the name of the file to be opened.  This name can be in
  1968. the form of a string or a symbol.  The OPEN function returns an
  1969. object of type FILE-STREAM if it succeeds in opening the
  1970. specified file.  It returns the value NIL if it fails.  In order
  1971. to manipulate the file, it is necessary to save the value
  1972. returned by the OPEN function.  This is usually done by
  1973. assigning it to a variable with the SETQ special form or by
  1974. binding it using LET or LET*.  Here is an example:
  1975.  
  1976.     (setq fp (open "init.lsp" :direction :input))
  1977.  
  1978. Evaluating this expression will result in the file "init.lsp"
  1979. being opened.  The file object that will be returned by the OPEN
  1980. function will be assigned to the variable "fp".
  1981.  
  1982. It is now possible to use the file for input.  To read an
  1983. expression from the file, just supply the value of the "fp"
  1984. variable as the optional "stream" argument to READ.
  1985.  
  1986.     (read fp)
  1987.  
  1988. Evaluating this expression will result in reading the first
  1989. expression from the file "init.lsp".  The expression will be
  1990. returned as the result of the READ function.  More expressions
  1991. can be read from the file using further calls to the READ
  1992. function.  When there are no more expressions to read, the READ
  1993. function will return NIL (or whatever value was supplied as the
  1994. second argument to READ).
  1995.  
  1996. Once you are done reading from the file, you should close it.
  1997. To close the file, use the following expression:
  1998.  
  1999.     (close fp)
  2000.  
  2001. Evaluating this expression will cause the file to be closed.
  2002.  
  2003.  
  2004.  
  2005.  
  2006. XLISP                       EXAMPLES                     Page 48
  2007.  
  2008.  
  2009. Output to a File
  2010.  
  2011. Writing to a file is pretty much the same as reading from one.
  2012. You need to open the file first.  This time you should use the
  2013. OPEN function to indicate that you will do output to the file.
  2014. For example:
  2015.  
  2016.     (setq fp (open "test.dat" :direction :output))
  2017.  
  2018. Evaluating this expression will open the file "test.dat" for
  2019. output.  If the file already exists, its current contents will
  2020. be discarded.  If it doesn't already exist, it will be created.
  2021. In any case, a FILE-STREAM object will be returned by the OPEN
  2022. function.  This file object will be assigned to the "fp"
  2023. variable.
  2024.  
  2025. It is now possible to write to this file by supplying the value
  2026. of the "fp" variable as the optional "stream" parameter in the
  2027. PRINT function.
  2028.  
  2029.     (print "Hello there" fp)
  2030.  
  2031. Evaluating this expression will result in the string "Hello
  2032. there" being written to the file "test.dat".  More data can be
  2033. written to the file using the same technique.
  2034.  
  2035. Once you are done writing to the file, you should close it.
  2036. Closing an output file is just like closing an input file.
  2037.  
  2038.     (close fp)
  2039.  
  2040. Evaluating this expression will close the output file and make
  2041. it permanent.
  2042.  
  2043.  
  2044.  
  2045.  
  2046. XLISP                       EXAMPLES                     Page 49
  2047.  
  2048.  
  2049. A Slightly More Complicated File Example
  2050.  
  2051. This example shows how to open a file, read each Lisp expression
  2052. from the file and print it.  It demonstrates the use of files
  2053. and the use of the optional "stream" argument to the READ
  2054. function.
  2055.  
  2056.     (do* ((fp (open "test.dat" :direction :input))
  2057.       (ex (read fp) (read fp)))
  2058.      ((null ex) nil)
  2059.       (print ex))
  2060.  
  2061.  
  2062.